package com.haoxi.gateway.test.message;

import java.util.Date;
import java.text.SimpleDateFormat;
import com.haoxi.gateway.test.util.TypeConvert;

public class CMPP30StatusRpt extends CMPPMessage {
    public String toString() {
        String tmpStr = "CMPP_StatusRpt: ";
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nmsgId=").append(
                getMsgId())));
        tmpStr = String.valueOf(String.valueOf((new StringBuffer(String
                .valueOf(String.valueOf(tmpStr)))).append("\r\nStat=").append(
                getStat())));
        tmpStr = String.valueOf(tmpStr);
        return tmpStr;
    }

    public int getCommandId() {
        return 0;
    }

    private byte[] buf;

    public CMPP30StatusRpt(byte[] submitmsgID, String Stat, Date Submit_time,
            Date Done_time, String Dest_terminal_Id, int SMSC_sequence) {
        buf = new byte[60];
        SimpleDateFormat format = new SimpleDateFormat("yyMMddHHmm");
        String Submit_timestr = format.format(Submit_time);
        String Done_timestr = format.format(Done_time);
        System.arraycopy(submitmsgID, 0, buf, 0, 8);
        System.arraycopy(Stat.getBytes(), 0, buf, 8, 7);
        System.arraycopy(Submit_timestr.getBytes(), 0, buf, 15, 10);
        System.arraycopy(Done_timestr.getBytes(), 0, buf, 25, 10);
        System.arraycopy(Dest_terminal_Id.getBytes(), 0, buf, 35,
                Dest_terminal_Id.length());
        TypeConvert.int2byte(SMSC_sequence, buf, 56);

    }

    public String getStat() {
        byte[] tmp = new byte[7];
        System.arraycopy(buf, 8, tmp, 0, 7);
        String Stat = (new String(tmp)).trim();
        if (Stat.indexOf(0) >= 0)
            return Stat.substring(0, Stat.indexOf(0));
        else
            return Stat;
    }

    public String getMsgId() {
        byte[] tmp = new byte[8];
        System.arraycopy(this.buf, 0, tmp, 0, 8);
        String msgID = "";
        for (int i = 0; i < tmp.length; i++) {
            msgID = msgID + tmp[i];
        }
        return msgID;
    }

    public byte[] getContents() {
        return buf;
    }
}
